﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpiderHelper.Model
{
    /// <summary>
    /// 采集频道
    /// </summary>
    public class CollectionChannel
    {
        /// <summary>
        /// 编号
        /// </summary>
        public int Id { get; set; }
        /// <summary>
        /// 所在站点ID
        /// </summary>
        public int SiteId { get; set; }

        /// <summary>
        /// 频道名称
        /// </summary>
        public string ChannelName { get; set; }
        /// <summary>
        /// 频道访问路径
        /// </summary>
        public string ChannelURL { get; set; }
        /// <summary>
        /// 频道类型
        /// </summary>
        public string Type { get; set; }
        /// <summary>
        /// 字符集编码
        /// </summary>
        public string Encode { get; set; }
        /// <summary>
        /// 是否订阅
        /// </summary>
        public int Subscribe { get; set; }



        public CollectionChannel()
        {
            this.Id = int.MinValue;
            this.SiteId = int.MinValue;
            this.Subscribe = int.MinValue;
        }

        public List<CollectionChannel> GetList()
        {
            List<CollectionChannel> _channels = new List<CollectionChannel>();
            CollectionChannel channel = new CollectionChannel();
            channel.Subscribe = 1;
            List<object> objs = Common.ADO.DBManager.GetSomeObject(channel);
            foreach (CollectionChannel s in objs)
            {
                _channels.Add(s);
            }
            _channels = _channels.OrderBy(a => a.Id).ToList();
            return _channels;
        }

        public List<CollectionChannel> GetList(int siteId)
        {
            DavidDB.ADO.DBManager db = new DavidDB.ADO.DBManager();
            List<CollectionChannel> _channels = new List<CollectionChannel>();
            CollectionChannel channel = new CollectionChannel();
            channel.SiteId = siteId;
            channel.Subscribe = 1;
            List<object> objs = db.GetSomeObject(channel);
            foreach (CollectionChannel s in objs)
            {
                _channels.Add(s);
            }
            _channels = _channels.OrderBy(a => a.Id).ToList();
            db.Commit();
            db.Dispose();
            return _channels;
        }
    }
}
